<?php

namespace App\Http\Controllers\Home;

use App\Http\Model\Article;
use App\Http\Model\Navs;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\View;

class CommonController extends Controller
{
    public function __construct()
    {
        //自定义导航
        $navs = Navs::orderBy('nav_order','asc')->get();

        //最新发布的文章8篇
        $news = Article::orderBy('art_time','desc')->take(8)->get();

        //点击量最高的5篇文章
        $hot_5 = Article::orderBy('art_view','desc')->take(5)->get();

        //向每个模版分配公共数据，只要是在控制器中载入模版
        View::share('navs',$navs);
        View::share('news',$news);
        View::share('hot_5',$hot_5);
    }
}
